import { Component, OnInit } from '@angular/core';
import { AlertController } from '@ionic/angular';
import { Router } from '@angular/router';
import { myEnterAnimations } from '../animations/enter';
import { myLeaveAnimations } from '../animations/leave';

@Component({
  selector: 'app-alert',
  templateUrl: './alert.page.html',
  styleUrls: ['./alert.page.scss'],
})
export class AlertPage implements OnInit {

  constructor(public alertController: AlertController,private router: Router) { }

  ngOnInit() {
  }

  gotohome(){
    this.router.navigate(['/'])
  }

  async presentAlert() {
    const alert = await this.alertController.create({
      header: 'Alert',
      subHeader: 'Subtitle',
      message: 'This is an alert message.',
      buttons: ['OK']
    });
    await alert.present();
  }

  async presentAlerta() {
    const alert = await this.alertController.create({
      header: 'Alert',
      subHeader: 'Subtitle',
      animated: false,
      message: 'This is an alert message.',
      buttons: ['OK']
    });
    await alert.present();
  }

  async presentAlertb() {
    const alert = await this.alertController.create({
      header: 'Alert',
      subHeader: 'Subtitle',
      backdropDismiss: false,
      message: 'This is an alert message.',
      buttons: ['OK']
    });
    await alert.present();
  }

  async presentAlertc() {
    const alert = await this.alertController.create({
      header: 'Alert',
      subHeader: 'Subtitle',
      backdropDismiss: false,
      message: 'This is an alert message.',
      buttons: ['确定','取消']
    });
    await alert.present();
  }

  async presentAlertd() {
    const alert = await this.alertController.create({
      header: 'Alert',
      subHeader: 'Subtitle',
      enterAnimation: myEnterAnimations,
      leaveAnimation: myLeaveAnimations,
      message: 'This is an alert message.',
      buttons: ['确定']
    });
    await alert.present();
  }

  async presentAlerte() {
    const alert = await this.alertController.create({
      header: '自定义标题',
      subHeader: '自定义副标题',
      enterAnimation: myEnterAnimations,
      message: 'This is an alert message.',
      buttons: ['确定']
    });
    await alert.present();
  }

  async presentAlertf() {
    const alert = await this.alertController.create({
      header: '自定义标题',
      subHeader: '自定义副标题',
      inputs: [
        {
          name: 'name1',
          type: 'text',
          placeholder: 'Placeholder 1'
        },
        {
          name: 'name2',
          type: 'text',
          id: 'name2-id',
          value: 'hello',
          placeholder: 'Placeholder 2'
        },
        {
          name: 'name3',
          value: 'http://ionicframework.com',
          type: 'url',
          placeholder: 'Favorite site ever'
        },
        {
          name: 'name4',
          type: 'date',
          min: '2017-03-01',
          max: '2018-01-12'
        },
        {
          name: 'name5',
          type: 'date'
        },
        {
          name: 'name6',
          type: 'number',
          min: -5,
          max: 10
        },
        {
          name: 'name7',
          type: 'number'
        }
      ],
      message: 'This is an alert message.',
      buttons: ['确定']
    });
    await alert.present();
  }

  async presentAlertg() {
    const alert = await this.alertController.create({
      header: '自定义标题',
      subHeader: '自定义副标题',
      keyboardClose: true,
      message: 'This is an alert message.',
      buttons: ['确定']
    });
    await alert.present();
  }

  async presentAlerth() {
    const alert = await this.alertController.create({
      header: '自定义标题',
      subHeader: '自定义副标题',
      message: '这是自定义的message.',
      buttons: ['确定']
    });
    await alert.present();
  }

  async presentAlerti() {
    const alert = await this.alertController.create({
      header: '自定义标题',
      subHeader: '自定义副标题',
      message: '这是自定义的message.',
      mode: "md",
      buttons: ['确定']
    });
    await alert.present();
  }

  async presentAlertj() {
    const alert = await this.alertController.create({
      header: '自定义标题',
      subHeader: '自定义副标题',
      message: '这是自定义的message.',
      translucent: true,
      buttons: ['确定']
    });
    await alert.present();
  }

  async presentAlertk() {
    const alert = await this.alertController.create({
      header: '自定义标题',
      subHeader: '自定义副标题',
      message: '这是自定义的message.',
      translucent: true,
      buttons: ['确定']
    });
    alert.dismiss().then(data=>{console.log("执行dismiss")});
    alert.present().then(data=>{console.log("执行present")});
    alert.onDidDismiss().then(data=>{console.log("执行onDidDismiss")});
    alert.onWillDismiss().then(data=>{console.log("执行onWillDismiss")});
  }

  async presentAlertl() {
    const alert = await this.alertController.create({
      header: '自定义标题',
      subHeader: '自定义副标题',
      message: '这是自定义的message.',
      cssClass: 'myalertclass',
      buttons: [
        {
          text: '确定',
          role: 'cancel',
          cssClass: 'secondary',
          handler: () => {
            console.log('Confirm Cancel');
          }
        }
      ]
    });
    await alert.present();
  }
}
